package com.gopay.common.cps.dao.cbrmb.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.cbrmb.CbRmbRetranmissRecordDAO;
import com.gopay.common.domain.cbrmb.CbRmbAllocationOrderLogs;
import com.gopay.common.domain.cbrmb.CbRmbRetranmissRecord;
import com.gopay.common.exception.GopayException;

@Repository(value="cbRmbRetranmissRecordDAO")
public class CbRmbRetranmissRecordDAOImpl extends BaseDAOImpl<CbRmbRetranmissRecord, String> implements CbRmbRetranmissRecordDAO {


	@Override
	public CbRmbRetranmissRecord findByGopayOrderId(String gopayOrderId) {
		Map<String,Object> params = new HashMap<>();
    	params.put("gopayOrderId", gopayOrderId);
        String hql = "from CbRmbRetranmissRecord m where m.gopayOrderId=:gopayOrderId";
        List<CbRmbRetranmissRecord> ss = findByHql(hql,params);
        return (null == ss || 0 == ss.size()) ? null : ss.get(0);
	}

	@Override
	public CbRmbRetranmissRecord save(CbRmbRetranmissRecord entity) {
		super.save(entity);
        return entity;
	}
	
	@Override
    public List<CbRmbRetranmissRecord> getListByGopayOrderId(String gopayOrderId,Date startTime, Date endTime) throws GopayException {
        String hql = "from CbRmbRetranmissRecord where gopayOrderId= :orderId and createTime >= :st and createTime <= :et order by createTime ASC";
        Map<String, Object> param = new HashMap<>();
        param.put("orderId", gopayOrderId);
        param.put("st", startTime);
        param.put("et", endTime);
        return super.findByHql(hql, param);
    }

}
